using System;
using UnityEngine;
using UnityEngine.UI;

namespace MaterialUI
{
	[AddComponentMenu("MaterialUI/Dialogs/Day Picker Item", 100)]
	public class DialogDatePickerDayItem : MonoBehaviour
	{
		[SerializeField]
		private Text m_Text;

		[SerializeField]
		private Toggle m_Toggle;

		[SerializeField]
		private VectorImage m_SelectedImage;

		private DateTime m_DateTime;

		private Action<DialogDatePickerDayItem, bool> m_OnItemValueChanged;

		public Text text => m_Text;

		public Toggle toggle => m_Toggle;

		public VectorImage selectedImage => m_SelectedImage;

		public DateTime dateTime => m_DateTime;

		public void Init(DateTime dateTime, Action<DialogDatePickerDayItem, bool> onItemValueChanged)
		{
			m_DateTime = dateTime;
			m_OnItemValueChanged = onItemValueChanged;
			base.transform.localScale = Vector3.one;
			m_Text.text = m_DateTime.Day.ToString();
		}

		public void UpdateState(DateTime currentDate)
		{
			bool flag = m_DateTime.Month == currentDate.Month && !m_DateTime.Equals(default(DateTime));
			toggle.interactable = flag;
			m_Text.gameObject.SetActive(flag);
			if (flag)
			{
				bool flag2 = m_DateTime.Day == DateTime.Now.Day && m_DateTime.Month == DateTime.Now.Month && m_DateTime.Year == DateTime.Now.Year;
				m_Text.fontStyle = (flag2 ? FontStyle.Bold : FontStyle.Normal);
				if (m_DateTime.Equals(currentDate))
				{
					toggle.isOn = true;
				}
			}
		}

		public void OnItemValueChange()
		{
			m_Text.color = ((!toggle.isOn) ? Color.black : Color.white);
			if (m_OnItemValueChanged != null)
			{
				m_OnItemValueChanged(this, toggle.isOn);
			}
		}
	}
}
